package com.jsj.subway.ai.agent.rag.config;


import com.jsj.subway.ai.agent.rag.KbApiClient;
import com.jsj.subway.ai.agent.rag.KbClient;
import lombok.Data;
import okhttp3.ConnectionPool;
import okhttp3.OkHttpClient;
import org.springframework.beans.factory.InitializingBean;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.List;
import java.util.concurrent.TimeUnit;

@Configuration
@ConfigurationProperties("kb")
@Data
public class KbConfig implements InitializingBean {

    String apiHost;

    private List<String> apiKeys;

    @Override
    public void afterPropertiesSet() throws Exception {

    }

    @Bean
    public KbClient stApiClient(){
        OkHttpClient OK_HTTP_CLIENT = new OkHttpClient.Builder()
                .connectTimeout(1, TimeUnit.MINUTES)
                .writeTimeout(60, TimeUnit.SECONDS)
                .readTimeout(120, TimeUnit.SECONDS)
//                .proxy(proxy)
                .connectionPool(new ConnectionPool(100, 1L, TimeUnit.MINUTES)).build();
        KbClient client = KbApiClient.builder()
                // keys
                .apiKey(apiKeys)
                //自己做了代理就传代理地址，没有可不不传
                .okHttpClient(OK_HTTP_CLIENT)
                .apiHost(apiHost)
                .build();
        return client;
    }
}